#!/bin/bash
#功能函数
funcs=`which functions.sh`
if [ "$funcs" != "" ] ;then
    echo "funcs=$funcs"
    . $funcs
else
    funcs=./functions.sh
    if [ "$funcs" != "" ] ;then
	echo "funcs=$funcs"
	. $funcs
    else
	echo "./functions.sh not exist!"
	return
    fi
fi
CP="cp -rvf"
PARSEINI=`which parseini.shc`
Please_set_the_work_directory="设置源代码所在的工作目录......" 
default_configs_path=/usr/local/bin/projects/configs
 default_release_dir=$HOME/workspace/gphone/release/
projects_ini=/tmp/projects.ini
echo "aaaaa=`sh_get_svn_hostip`"
get-config.shc http://`sh_get_svn_hostip`/repositories/DocsAndTools/scripts/configs/public/projects.ini $projects_ini

function sh_get_project_tag()
{
local projects_tags=
local project_config_fs=
projects_tags=`cat $projects_ini |grep "\[*\]" |tr -d '[|]'|tr '\n' ' '`
projects_tags=`echo $projects_tags | sed 's/global//g'`
for f in $projects_tags
do
ac_name="`$PARSEINI "$projects_ini" get "$f" "project_name"`"
ac_des="`$PARSEINI  "$projects_ini" get "$f" "project_des"`"
if [ -z "$ac_des" ]; then
  ac_tags="$ac_tags  ${f}_${ac_name}"
else
  ac_tags="$ac_tags  ${f}_${ac_name}_${ac_des}"
fi
done
ac_tag=`sh_menu_select "$ac_tags"`
ac_tag=`echo "$ac_tag"|awk -F _ '{print $1}'`
echo $ac_tag
}


#
function sh_get_build_id()
{
    local ac_build_id=
    echo $1 >&2
    ac_build_id="`cat ${1}/build/core/build_id.mk |grep BUILD_ID=`"
    echo ${ac_build_id##*=}
}
#
function upper_to_lower()
{
local ac_lower=
ac_lower=`echo $1 |tr A-Z  a-z`
echo $ac_lower
}
#
function lower_to_upper()
{
local ac_upper=
ac_upper=`echo $1 |tr a-z A-Z`
echo $ac_upper
}

####
function check_work_copy()
{
    local ac_title=
    local ac_work_copy_dir=
    local ac_dir=
    if [ -z "$1" ]; then
        exit
    fi
    if [ -z "$2" ]; then
	ac_title="Please set the work directory"
    else
	ac_title="$2"
    fi
    ac_work_copy_dir=$1 
    ac_dir=`dirname $ac_work_copy_dir`  
    while [ ! -d $ac_dir/$ac_work_copy_dir/.svn ]
    do
	#ac_work_dir=`dirname $ac_work_copy_dir`
        echo "$ac_work_copy_dir/.svn not exist" >&2
        ls $ac_dir >&2
        ac_work_copy_dir=`question  "$ac_title"  2  $ac_work_copy_dir`
    done
    echo $ac_dir/$ac_work_copy_dir
}
####
function create_tar_package() 
{
    echoTextBlue  "创建压缩文件......"
    if [ -n "$1" ] && test -d $1; then
        if [ -z "$2" ]; then
            local menu_lists="`ls -Ftr $1|grep "/"`"
            echo "$menu_lists"
            ac_dir=`sh_menu_select2 "$menu_lists"`
            echo "ac_dir=$ac_dir"
        else
	    ac_dir=$2
        fi
        if test -d $1/$ac_dir; then
            cd $1
            tar -cvzf `basename $1/$ac_dir`.tar.gz $ac_dir
            echoTextRed "tar包： ${1}/`basename $1/$ac_dir`.tar.gz  已经生成！！"
        fi
    fi
}
####
function create_update_patchs()
{
local MODE=
local scriptmode=auto
local mode=auto
local createall=false
local old_android_svn_v=
if [ -n "$1" ]; then
    mode=$1
fi
if [ -n "$2" ]; then
    createall=$2
fi

local work_dir=`question  $Please_set_the_work_directory  2  $work_dir`
local project_android_dir=`check_work_copy $work_dir/$project_name  "===>选择android主线源代码"`
local project_android_out=${project_android_dir}/out/target/product/${product_name}
local project_update_dir=

if [ "$project_type" = "qcom" ]; then
CUR_FILES_PACKAGE=`ls ${project_android_out}/obj/PACKAGING/target_files_intermediates/*-target_files-*.zip`
local project_modem_dir=`check_work_copy $work_dir/$project_name  "===>选择modem代码"`
local project_modem_out=${project_modem_dir}/AMSS/products/${chip_type}/build/ms/bin/${build_for}
  nimo_hboot_v=`cat $project_android_dir/vendor/bbk/$project_name/Products.mk |grep BBK_PRODUCT_HBOOT_VERSION |awk '{print $3}'`
nimo_android_v=`cat $project_android_dir/vendor/bbk/$project_name/Products.mk |grep BBK_PRODUCT_VERSION |awk '{print $3}' |tr -d '[A-Z]|[a-z]|_'`
  nimo_radio_v=`cat $project_android_dir/vendor/bbk/$project_name/Products.mk |grep BBK_PRODUCT_RADIO_VERSION |awk '{print $3}'`
project_update_zip=$project_android_out/update.zip
target_files=`ls $updates_dir/*/target*.zip`
elif [ "$project_type" = "mtk" ]; then
nimo_android_v=`cat $project_android_dir/mediatek/config/common/ProjectConfig.mk |grep MTK_BUILD_VERNO |awk  '{print $3}'`
nimo_android_v=${nimo_android_v##*_} 
project_update_zip=$project_android_out/update.zip
target_files=`ls $updates_dir/*/target*.zip`
fi
##
OTA_CMD=$project_android_dir/build/tools/releasetools/ota_from_target_files
HOST_OUT=$project_android_dir/out/host/linux-x86
KEY_CERT_PAIR=$project_android_dir/build/target/product/security/testkey

if test -f build/core/version_defaults.mk; then
    AC_PLATFORM_VERSION=`grep "PLATFORM_VERSION :=" build/core/version_defaults.mk  |awk '{print $3}'`
    if [ -n "`echo $AC_PLATFORM_VERSION  |grep 2.2`" ]; then
        MODE="-m $scriptmode"
    else
        MODE=
    fi
fi
echo "MODE=$MODE"
project_update_dir=$updates_dir/${nimo_android_v}
mkdir -pv $project_update_dir
android_svn_v="`sh_get_svn_committed_no_from_copy $project_android_dir`"
android_svn_v=`question  "Please set the svn version of $project_android_dir committed is:"  2  ${android_svn_v}`

$CP    $project_modem_out/amss.mbn      $project_update_dir/radio_${nimo_radio_v}.img
$CP  $project_android_out/appsboot.mbn  $project_update_dir/hboot_${nimo_hboot_v}.img

#拷贝生成patch包所需的zip文件,update.zip...
$CP $project_update_zip  $project_update_dir/update-full_${nimo_android_v}_r${android_svn_v}_trunk.zip
if [ "$mode" = "auto" ]; then
echoTextGreen "完整升级包"
files_update_full=`ls $updates_dir/*/update-full*.zip`
echoTextGreen "补丁升级包"
files_update_patch=`ls $updates_dir/*/update-patch*.zip`
echoTextGreen "压缩包"
if test -f ${CUR_FILES_PACKAGE}; then
    $CP ${CUR_FILES_PACKAGE} $project_update_dir/target-files_${nimo_android_v}_r${android_svn_v}.zip
else
    echoTextRed "${CUR_FILES_PACKAGE} not exist!! "
    return
fi

echo "target_files=$target_files"


for file in $target_files
do
    #target-files_1.1.01_r1833_trunk.zip
    old_android_svn_v=`echo $file |tr '_' ' '|awk '{print $3}'`
    old_nimo_android_v=`echo $file |tr '_' ' '|awk '{print $2}'`
    echo "nimo_android_v=$nimo_android_v old_nimo_android_v=$old_nimo_android_v"
    if ! `sh_cmp_version $nimo_android_v $old_nimo_android_v`; then
        echoTextRed "当前nimo android 版本: $nimo_android_v 对 $old_nimo_android_v 版本进行 patch 操作 ......"
    else
        echoTextRed "版本不匹配！！**********"
        continue
    fi
    OLD_FILES_PACKAGE=$file   
    PATCH_OTA_PACKAGE=$project_update_dir/update-patch_${nimo_android_v}_for_${old_nimo_android_v}_r${android_svn_v}_for_${old_android_svn_v}_trunk.zip
    if test -f $OLD_FILES_PACKAGE && test -f $CUR_FILES_PACKAGE; then
    echoTextBlue "$OTA_CMD -i  $OLD_FILES_PACKAGE  $MODE  -p $HOST_OUT -k $KEY_CERT_PAIR $CUR_FILES_PACKAGE $PATCH_OTA_PACKAGE" 
    $OTA_CMD -i  $OLD_FILES_PACKAGE  $MODE  -p $HOST_OUT -k $KEY_CERT_PAIR $CUR_FILES_PACKAGE $PATCH_OTA_PACKAGE
    else
        echo "OLD_FILES_PACKAGE=$file"
    fi 
done

else
echoTextBlue "请选折上一版本的 *-target_files-*.zip 文件 ......"
result=`question  "设置  *-target_files-*.zip 文件所在的目录，默认为:"  2  $updates_dir/` 
OLD_FILES_PACKAGE=`sh_ls "$result/*/*/*-target_files-*.zip" files`

echoTextRed "请选中当前版本的 *-target_files-*.zip 文件 ......"
CUR_FILES_PACKAGE=`sh_ls "$ANDROID_BUILD_TOP/out/target/product/$TARGET_PRODUCT/obj/PACKAGING/target_files_intermediates/*-target_files-*.zip" files`
PATCH_OTA_PACKAGE=$ANDROID_PRODUCT_OUT/update-patch.zip


if [ -n "$OLD_FILES_PACKAGE" ]; then
echoTextBlue "./build/tools/releasetools/ota_from_target_files -i  $OLD_FILES_PACKAGE  $MODE -p $HOST_OUT -k $KEY_CERT_PAIR $CUR_FILES_PACKAGE $PATCH_OTA_PACKAGE"
if test ! -f $CUR_FILES_PACKAGE; then return; fi
echoTextBlue "$OTA_CMD -i  $OLD_FILES_PACKAGE  $MODE  -p $HOST_OUT -k $KEY_CERT_PAIR $CUR_FILES_PACKAGE $PATCH_OTA_PACKAGE"
$OTA_CMD -i  $OLD_FILES_PACKAGE  $MODE  -p $HOST_OUT -k $KEY_CERT_PAIR $CUR_FILES_PACKAGE $PATCH_OTA_PACKAGE
fi
fi #end mode
}


#####################################################################################
#发布编译过程的中间文件
static_java_libs="
bbk-common
android-common
com.android.inputmethod.pinyin.lib 
com.android.phone.common 
com.mediatek.CellConnUtil 
com.mediatek.wsp 
file_sharing_client_lib 
guava 
jsr305 
libarity 
libbonjour 
libftplet 
wsdsrv_ksoap2_lib"

java_libs="
bbk-common
android.policy 
android.test.runner 
bouncycastle 
com.mediatek.framework 
core
core-junit
ext 
framework 
javax.obex"

jni_libs="
libfm_jni 
libgalleryjni 
libjni_pinyinime 
libmtkcalibrator_jni 
libnfc_jni 
libp2pjni 
libp2psdjni 
libquake
libWnnEngDic 
libWnnJpnDic 
libwnndict"

shared_o="
crtbegin_dynamic.o
crtend_android.o
crtbegin_static.o
crtend_so.o
crtbegin_so.o"

shared_libs="
libacdk
libandroid_runtime
libaudioflinger
libbessound_mtk
libbinder
libbluetoothem_mtk
libc
libcamera_client
libcameracustom
libcrypto
libcustom_nvram
libcutils
libwpa_client
libdiskconfig
libdl
libdrmframework
libfile_op
libfm
libhardware
libhardware_legacy
libhwm
liblog
libnativehelper
libm
libmatv_cust
libmdlogger_ctrl_jni
libmedia
libmhal
libmpodecoder
libnativehelper
libnetutils
libnvram
libcustom_nvram
libomx_amrenc_sharedlibrary
libpixelflinger
libskia
libssl
libstdc++
libstlport
libsysutils
libui
libutils
libmdlogger_ctrl
libz
"

static_libs="
libbz 
libc 
libche 
libCustomWifi 
libcutils 
libdiagnose 
libelf 
libinterface
liblog
libm
libmatvctrl 
libmincrypt 
libminiui 
libminzip 
libMST 
libmtd_util 
libmtdutil 
libpcap 
libpixelflinger_static 
libpng 
libsbchk 
libstdc++ 
libtommath 
libunz 
libvpx 
lib_wifi_em 
libxml2 
libz"

res_packages="framework-res mtkBase-res"



function copy_files_to()
{
local file_list="$1"
local to=$2
if [ -z "$to" ]; then
  to=`question  "请指定存release文件的目录:"  2  $to`
fi
cp.sh "$file_list" $to
}

function release_mtk_for_eclipse()
{
echoTextBlue "生成 android.jar包用户eclipse开发"
local ac_java_libs="$java_libs bbk-common"
local out_dir=/tmp/for_eclipse
rm $out_dir -rf
mkdir $out_dir  -pv
###所有资源包

ac_android_jars=`ls  ~/programes/android-sdk-linux_x86/platforms/*/android.jar`
echoTextBlue "============选择一个 android.jar 文件 ============"
ac_android_jar=`sh_menu_select2 "$ac_android_jars"`
cp -rvf $ac_android_jar $out_dir 
cp -rvf $ac_android_jar $out_dir/androidb.jar
all_res_packages=
for df in $res_packages
do
  all_res_packages="$all_res_packages $src/target/common/obj/APPS/${df}_intermediates/package-export.apk"
  cp $src/target/common/obj/APPS/${df}_intermediates/package-export.apk $out_dir/${df}.zip -rvf 
  mkdir $out_dir/${df} -pv; 
  unzip -q $out_dir/${df}.zip -d  $out_dir/${df}; 
  rm META-INF AndroidManifest.xml -rf
  cd $out_dir
  jar uf android.jar -C ${df} .
  cd -
  rm  $out_dir/${df}* -rf
done
###所有java库
all_java_libs=
for df in  $java_libs
do
  all_java_libs="$all_java_libs  $src/target/common/obj/JAVA_LIBRARIES/${df}_intermediates/classes.jar"
  cp $src/target/common/obj/JAVA_LIBRARIES/${df}_intermediates/classes.jar  $out_dir/${df}.jar -rf
done
#cp --parents -rf $all_res_packages $all_java_libs $dst
}

function release_for_eclipse()
{
  release_mtk_for_eclipse
}

function release_out()
{

src=out
dst=/tmp/release
if [ -n "$1" ]; then
  src=$1
else
  ls out* -d 2>/dev/null
  src=`question  "请指定out目录:"  2  $src`
  if test ! -d $src; then
    echoTextRed "$src 目录不存在......"
    return
  fi
fi

###
host_files="
$src/host/linux-x86/bin
$src/host/linux-x86/etc
$src/host/linux-x86/framework
$src/host/linux-x86/lib
$src/host/linux-x86/usr"

host_files_for_framework="
`ls out/host/linux-x86/obj/STATIC_LIBRARIES/*/*.a`
"


###所有java库
all_java_libs=
for df in $static_java_libs $java_libs
do
  all_java_libs="$all_java_libs  $src/target/common/obj/JAVA_LIBRARIES/${df}_intermediates/"
done

###所有动态库
all_shared_libs=
for df in $jni_libs $shared_libs 
do
  all_shared_libs="$all_shared_libs $src/target/product/$product_name/obj/lib/${df}.so"
done
for df in $shared_o 
do
  all_shared_libs="$all_shared_libs $src/target/product/$product_name/obj/lib/${df}"
done

###所有静态库
all_static_libs=
for df in $static_libs
do
  all_static_libs="$all_static_libs `ls $src/target/product/$product_name/obj/STATIC_LIBRARIES/*/${df}.a 2>/dev/null`"
done

###所有资源包
all_res_packages=
for df in $res_packages
do
  all_res_packages="$all_res_packages $src/target/common/obj/APPS/${df}_intermediates/"
done

all_img_files="
$src/target/product/$product_name/root
$src/target/product/$product_name/recovery
$src/target/product/$product_name/system/
`ls $src/target/product/$product_name/*.img`
`ls $src/target/product/$product_name/*.bin`
$src/target/product/$product_name/*Android_scatter*.txt
$src/target/product/$product_name/DSP_BL
bootable/bootloader/uboot/uboot_$product_name.bin
bootable/bootloader/uboot/logo.bin
kernel/kernel_$product_name.bin
"
other_files="
$src/target/product/$product_name/obj/include
$src/target/product/$product_name/obj/SHARED_LBRARES/libskia_intermediates
$src/target/product/$product_name/obj/STATC_LBRARES/libfdlibm_intermediates
$src/target/product/$product_name/obj/STATC_LBRARES/libjavacore_intermediates
$src/target/product/$product_name/obj/STATC_LBRARES/libwebcore_intermediates"


echoTextRed   "host_files=$host_files"
echoTextGreen "all_java_libs=$all_java_libs"
echoTextBlue  "all_shared_libs=$all_shared_libs"
echoTextRed   "all_static_libs=$all_static_libs"
echoTextGreen "all_res_packages=$all_res_packages"
echoTextBlue  "all_img_files=$all_img_files"


menu_list="eclipse开发  上层应用开发    ndk开发     驱动开发          中间层开发      系统移植        所有"
value_list="for_eclipse  for_app     for_ndk    for_kernel      for_framwork   for_porting   for_all" 
echoTextBlue "请选择需要发布的内容......"
result=`sh_menu_select "$menu_list"  "$value_list"`
if [ -n "$2" ]; then
  dst=$2
else
  dst=/tmp/$result
fi

if [ "$result" = "for_eclipse" ]; then
  release_for_eclipse
  exit
  copy_files_to "$all_res_packages $all_java_libs " $dst
elif [ "$result" = "for_app" ]; then
  copy_files_to "$host_files $all_java_libs $all_res_packages $all_shared_libs $all_static_libs $all_img_files" $dst 
elif [ "$result" = "for_ndk" ]; then
  copy_files_to "$host_files $all_shared_libs $all_static_libs $all_img_files" $dst
elif [ "$result" = "for_kernel" ]; then
  copy_files_to "$host_files $all_img_files" $dst
elif [ "$result" = "for_framwork" ]; then
  copy_files_to "$host_files $host_files_for_framework $all_img_files" $dst
elif [ "$result" = "for_porting" ]; then
  copy_files_to "$host_files $all_img_files" $dst
else
  #copy_files_to "$all_static_libs" $dst
  copy_files_to "$host_files $all_java_libs $all_shared_libs  $all_res_packages $all_static_libs $all_img_files" $dst
fi
cd `dirname $dst`
tar -cvzf `basename $dst`.tar.gz `basename $dst`
cd -
}

#####################################################################################
#选择qcn文件
function select_qcn_file()
{
    local qcns_dir=
    local qcn_file=
    local qcn_file_name=
    local default_qcn_file=$default_release_dir/qcns/qcn001.qcn
    if sh_at_home; then
    local default_qcns_url=http://svn/repositories/TD1014/special/qcns
    else
    local default_qcns_url=http://smartphone/repositories/TD1014/special/qcns
    fi
    echo "Please select the qcn file" >&2
    qcns_dir=`dirname $default_qcn_file`
    if test ! -d $qcns_dir; then
        mkdir -pv $qcns_dir/../
        svn co $default_qcns_url  $qcns_dir/../qcns  
    fi
    qcn_file=`sh_ls  "$default_release_dir/*/*.qcn  $default_release_dir/*/*/*.qcn"  files`
    if [ "$qcn_file" = "" ]; then
        echo "qcn file not exist!" >&2
        return
    fi
    echo $qcn_file
}


function copy_qcom_output_files()
{
local product_name_lower=`echo $product_name |tr A-Z  a-z`
local ac_android_top=$1
local ac_modem_top=$2
local ac_image_dir=$3
if [ -n "$device_name" ]; then
project_android_imgs_dir=$ac_android_top/out/target/product/$device_name/
else
project_android_imgs_dir=$ac_android_top/out/target/product/$product_name/
fi
project_modem_imgs_dir=$ac_modem_top/AMSS/products/$chip_type/build/ms/bin/$build_for
mkdir -pv ${ac_image_dir}/${build_for}

echoTextBlue  "拷贝高通android镜像文件 from：$project_android_imgs_dir to $ac_image_dir ......"
echoTextBlue  "拷贝高通modem镜像文件   from：$project_modem_imgs_dir to $ac_image_dir/$build_for ......"

local aaa=`ls $project_android_imgs_dir/app*`
local copye_files1="$aaa"
local mmm="boot.img recovery.img system.img userdata.img"
local copye_files2="$mmm"

cp -rvf $project_modem_imgs_dir  $ac_image_dir 
for f in $copye_files1
do
    cp -rvf $f ${ac_image_dir}/${build_for}/
done

for f in $copye_files2
do
    cp -rvf $project_android_imgs_dir/$f ${ac_image_dir}/
done
}
#处理高通
function process_qcom()
{
#PD1007_C_V1.2.0-qcom-M76XXTSNCJNLA61601002-gingerbread_msm7627_ffa_r6169_TSNCJNLYM_r6139_branch.tar.gz
echoTextBlue "process_qcom"
local  updates_dir=$default_release_dir/$project_name/updates
local  images_dir=$default_release_dir/$project_name/images
local  qcn_file=
local  b_create_tar=
local  ac_image_dir=
if [ "$1" = "tar" ]; then
    create_tar_package $images_dir
elif [ "$1" = "patch" ] || [ "$1" = "update" ]; then
    create_update_patchs
else 
work_dir=`question  $Please_set_the_work_directory  2  $work_dir`
if  [ "$trunk_branch" = "trunk" ]; then
project_android_trunk_dir=`check_work_copy $work_dir/$project_name  "===>选择android主线源代码"`
project_modem_dir=`check_work_copy $work_dir/$project_name  "===>选择modem代码"`
elif [ "$trunk_branch" = "branch" ]; then
project_android_branch_dir=`check_work_copy $work_dir/$project_name  "===>选择android分支源代码"`
project_modem_dir=`check_work_copy $work_dir/$project_name  "===>选择modem代码"`
else
project_android_trunk_dir=`check_work_copy $work_dir/$project_name   "===>选择android主线源代码"`
project_android_branch_dir=`check_work_copy $work_dir/$project_name  "===>选择android分支源代码"`
project_modem_dir=`check_work_copy $work_dir/$project_name  "===>选择modem代码"`
fi
project_android_dirs="$project_android_trunk_dir $project_android_branch_dir"

if [ -z "$b_create_tar" ]; then
    result=`question "是否创建压缩包？" 1 no`
    if [  "$result" = "yes" ] ; then
       b_create_tar=true  
    else
       b_create_tar=false 
    fi
fi

qcn_file=`select_qcn_file $default_release_dir`


for project_android_dir in $project_android_dirs
do
ac_android_svn_ver="`sh_get_svn_committed_no_from_copy $project_android_dir`"
  ac_modem_svn_ver="`sh_get_svn_committed_no_from_copy $project_modem_dir`"
ac_android_svn_ver=`question  "Please set the svn version of $project_android_dir committed is:"  2  ${ac_android_svn_ver}`
  ac_modem_svn_ver=`question  "Please set the svn version of $project_modem_dir committed is:"  2  ${ac_modem_svn_ver}`

trunk_or_branch=`svn info $project_android_dir |grep URL |grep trunk`
if [ -n "$trunk_or_branch" ]; then
    trunk_or_branch=trunk
else
    trunk_or_branch=branch
fi
local image_dir=$images_dir/${project_name}-${project_type}-${build_id}-${product_name}-r${ac_android_svn_ver}_${build_for}_r${ac_modem_svn_ver}_${trunk_or_branch}
mkdir -pv $image_dir
copy_qcom_output_files  $project_android_dir  $project_modem_dir $image_dir
#拷贝qcn文件
echoTextBlue "拷贝qcn文件 $qcn_file......"
if [ -n "$qcn_file" ]; then
  if test -f $qcn_file; then
    $CP $qcn_file ${image_dir}/${build_for}
  fi
fi
ac_image_dirs="$ac_image_dirs $image_dir"
done
for ac_image_dir in $ac_image_dirs
do
    ##创建压缩包
    if [ "$b_create_tar" = "true" ]; then
        create_tar_package $images_dir `basename $ac_image_dir`
    fi
done

fi #end if tar
}

######################################################################################
#处理mtk
function copy_mtk_output_files()
{
local product_name_lower=`echo $product_name |tr A-Z  a-z`
local ac_top=$1
local ac_image_dir=$2	
if [ -n "$device_name" ]; then
project_imgs_dir=$ac_top/out/target/product/$device_name/
else
project_imgs_dir=$ac_top/out/target/product/$product_name/
fi
echoTextBlue  "拷贝高通mtk镜像文件 from：$project_imgs_dir to $ac_image_dir ......"
echo "cat $project_android_dir/mediatek/config/$product_name/ProjectConfig.mk |grep ^CUSTOM_MODEM |awk  '{print $3}'|tr -d '\r'"
local ac_modem_dir=`cat $project_android_dir/mediatek/config/$product_name/ProjectConfig.mk |grep ^CUSTOM_MODEM |awk  '{print $3}'|tr -d '\r'`
local cgenfiles=`ls $ac_top/mediatek/source/cgen/APDB_*`
cd $ac_top/mediatek/custom/common/modem/$ac_modem_dir/
local modem_dbs=`ls BPLGUInfo*`
local modem_dbs2=`ls DbgInfo_*`
modem_db=`sh_menu_select "$modem_dbs"`
modem_db2=`sh_menu_select "$modem_dbs2"`
modem_db2=$ac_top/mediatek/custom/common/modem/$ac_modem_dir/$modem_db2
local copye_files1="$cgenfiles $modem_db $modem_db2"
local imgs_files1="boot.img recovery.img system.img userdata.img cache.img fat.img apps.img"
local imgs_files2="preloader_${product_name_lower}.bin DSP_BL uboot_${product_name_lower}.bin secro.img logo.bin MBR EBR1 EBR2"
local config_files="*Android_scatter*.txt "
local other_files="ramdisk-recovery.img ramdisk.img  factory.ini  previous_build_config.mk"
local copye_files2="$imgs_files1 $imgs_files2 $config_files $other_files"
#备份内核中间文件
local copye_files3="kernel/vmlinux kernel/System.map"
for i in $copye_files1
do 
cp -rvfL $i  $ac_image_dir; 
done

for i in $copye_files2
do 
cd $project_imgs_dir
if test -f $i; then
  cp -rvfL $i  $ac_image_dir; 
fi
cd -
done
for i in $copye_files3
do
  x=`dirname $i`
  y=`basename $i`
  mkdir -pv $ac_image_dir/$x
  $CP $ac_top/$i $ac_image_dir/$x/
done
}

function porting_mtk()
{
echoTextBlue "porting mtk......"
if [ "$1" = "release" ]; then
  release_out $src $dst
  return
fi

####开始配置
echoTextGreen "修改配置文件支持32位系统编译......
external/clearsilver/arch.mk
external/clearsilver/cgi/Android.mk
external/clearsilver/cs/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
mediatek/build/tools/checkEnv.py"
result=`question "是否修改以上配置？" 1 yes`
if [ "$result" = "yes" ]; then
##
touch external/clearsilver/arch.mk
cat >external/clearsilver/arch.mk<<EOF
# added by yezhenhua to adjust 32 bit and 64bit system
build_arch := \$(shell uname -m)
ifeq (64,\$(findstring 64,\$(build_arch)))
	LOCAL_CFLAGS += -m64
	LOCAL_LDFLAGS += -m64
else
	LOCAL_CFLAGS += -m32
	LOCAL_LDFLAGS += -m32
endif


EOF
files_list="
external/clearsilver/util/Android.mk
external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/cs/Android.mk\"
for i in $files_list
do
sed -i 's#LOCAL_CFLAGS += -m64#\#for 32/64 bit system#g'  \$i
sed -i 's#LOCAL_LDFLAGS += -m64#include \$(LOCAL_PATH)/../arch.mk#g' \$i
done"
##
fi #修改配置
echoTextRed "mediatek/build/tools/checkEnv.py 文件需要手动修改"
echo -e "---------------
+	    elif int(number[0]) == 10 and int(number[1]) == 10:
+  		    self.flag = "OK"
-            self.flag = \"FAIL\"
+            self.flag = \"FAIL64\""

####增加环境变量设置脚本
echoTextGreen "增加脚本文件
functions.sh
make-boot.sh"
result=`question "是否增加以上脚本文件？" 1 yes`
if [ "$result" = "yes" ]; then
    if test -f /usr/local/bin/functions.sh; then
        cp /usr/local/bin/functions.sh ./ -rvf
    fi
fi

####移植lcm
####移植nand flash
####移植电源管理相关
####移植触摸屏
}
####
function process_mtk()
{
#PD1007_C_V1.2.0-qcom-M76XXTSNCJNLA61601002-gingerbread_msm7627_ffa_r6169_TSNCJNLYM_r6139_branch.tar.gz
#TD1104_undifined-mtk-alps-alps-w1126-20110701-gingerbread_nimo73_gb_r48_for_smt.tar.gz
#image20110830-TD1104_P30_R2.0_B_1.03-W11.34-GRJ22
echoTextBlue "process_mtk"
local updates_dir=$default_release_dir/$project_name/updates
local  images_dir=$default_release_dir/$project_name/images
local  b_create_tar=
local  ac_image_dir=
## 

if [ "$1" = "eclipse" ]; then
  release_mtk_for_eclipse
elif [ "$1" = "porting" ]; then
    porting_mtk 
elif [ "$1" = "release" ]; then
    release_out $src $dst
elif [ "$1" = "tar" ]; then
    create_tar_package $images_dir
elif [ "$1" = "patch" ] || [ "$1" = "update" ]; then
    create_update_patchs
else 
work_dir=`question  $Please_set_the_work_directory  2  $work_dir`
if  [ "$trunk_branch" = "trunk" ]; then
project_dirs1=`check_work_copy $work_dir/$project_name  "===>选择主线源代码"`
elif [ "$trunk_branch" = "branch" ]; then
project_dirs2=`check_work_copy $work_dir/$project_name  "===>选择分支源代码"`
else
project_dirs1=`check_work_copy $work_dir/$project_name  "===>选择主线源代码"`
project_dirs2=`check_work_copy $work_dir/$project_name  "===>选择分支源代码"`
fi
project_dirs="$project_dirs1 $project_dirs2"

if [ -z "$b_create_tar" ]; then
    result=`question "是否创建压缩包？" 1 no`
    if [  "$result" = "yes" ] ; then
       b_create_tar=true  
    else
       b_create_tar=false 
    fi
fi

for project_android_dir  in $project_dirs
do
ac_BBK_PRODUCT_VERSION=`cat $project_android_dir/mediatek/config/${product_name}/ProjectConfig.mk |grep BBK_PRODUCT_VERSION |sed '/^#/d'|awk  '{print $3}'|tr -d '\r'`
ac_MTK_WEEK_NO=`cat $project_android_dir/mediatek/config/common/ProjectConfig.mk |grep MTK_WEEK_NO |awk  '{print $3}'|tr -d '\r'`

ac_modem_ver=`strings ${project_android_dir}/out/target/product/${product_name}/system/etc/firmware/modem.img |grep MAUI |grep BIN`
ac_modem_ver=${ac_modem_ver#*.} 
ac_modem_ver=${ac_modem_ver%%.*}
ac_modem_ver=`echo $ac_modem_ver|tr '_' '.'`
ac_modem_ver=${ac_modem_ver#*.} 
ac_modem_ver=${ac_modem_ver#*.} 
echo "ac_modem_ver=$ac_modem_ver"


ac_android_svn_ver="`sh_get_svn_committed_no_from_copy $project_android_dir`"
ac_android_svn_ver=`question  "Please set the svn version of $project_android_dir committed is:"  2  ${ac_android_svn_ver}`

ac_apps_svn_ver=`cat ${project_android_dir}/packages/.version`
ac_apps_svn_ver=`question  "Please set the svn version of ${project_android_dir}/packages/.version:" 2 ${ac_apps_svn_ver}`

trunk_or_branch=`svn info $project_android_dir |grep URL |grep trunk`
if [ -n "$trunk_or_branch" ]; then
    trunk_or_branch=trunk
else
    trunk_or_branch=branch
fi

ac_additional_info=`question  "输入补充信息:"  2 `
if [ -n "$ac_additional_info" ]; then
ac_additional_info=${ac_additional_info}
fi

if [ -n "$ac_BBK_PRODUCT_VERSION" ]; then
local image_dir=$images_dir/${ac_BBK_PRODUCT_VERSION}-${project_type}-`sh_get_build_id $project_android_dir`-${product_name}-r${ac_android_svn_ver}-${ac_modem_ver}-appR${ac_apps_svn_ver}${ac_additional_info}
else
local image_dir=$images_dir/${project_name}_${project_type}_`sh_get_build_id $project_android_dir`_${product_name}-r${ac_android_svn_ver}_${ac_modem_ver}_${trunk_or_branch}${ac_additional_info}
fi

echo "image_dir=$image_dir"
mkdir -pv $image_dir
copy_mtk_output_files  $project_android_dir  $image_dir
ac_image_dirs="$ac_image_dirs $image_dir"
done
for ac_image_dir in $ac_image_dirs
do
    ##创建压缩包
    if [ "$b_create_tar" = "true" ]; then
        create_tar_package $images_dir `basename $ac_image_dir`
    fi
done
fi #endif tar
}
######################################################################################
##########脚本入口
mode=images
while test $# != 0
do
    case $1 in
	-m)
	    shift
	    mode=$1
	    ;;
	-b)
	    shift
	    trunk_branch=$1
	    ;;
	-dst)
	    shift
	    dst=$1
	    ;;
	-src)
	    shift
	    src=$1
	    ;;
        *)
	   ac_project=$1
	   ;;
       esac
       shift
done
#选择项目
project_tag=`sh_get_project_tag $default_configs_path`
echo "project_tag=$project_tag"
if [ -z "$project_name" ]; then
project_name="`$PARSEINI "$projects_ini" get "$project_tag" "project_name"`"
fi
if [ -z "$project_type" ]; then
project_type="`$PARSEINI "$projects_ini" get "$project_tag" "project_type"`"
fi
if [ -z "$product_name" ]; then
product_name="`$PARSEINI "$projects_ini" get "$project_tag" "product_name"`"
fi
if [ -z "$work_dir" ]; then
work_dir="`$PARSEINI "$projects_ini" get "$project_tag" "work_dir"`"
fi
work_dir=`echo $work_dir |sed "s@~@$HOME@g"`
echo "work_dir=$work_dir"
echo "$product_name"
echo "process_$project_type $mode"
process_$project_type $mode
exit

svn merge -r  5430:5401 AMSS/products/76XX/drivers/adc/adc_ffa7500.c
svn merge -r  5430:5401 AMSS/products/76XX/drivers/chg/charger.c
svn merge -r  5430:5401 AMSS/products/76XX/drivers/chg/charger.h



